<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width='device-width', initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../Universal.css">
</head>
<body>
    
    <div id="cnblogs_post_body" class="blogpost-body">
        <h2>注释</h2>
    <p>注释用来解释和说明程序的文字，注释是不会被执行的.</p>
    <p>单行注释</p>
    <div class="cnblogs_code">
    <pre><span style="color: rgba(0, 128, 0, 1)">//<span class="fontstyle0">这是一条单行注释 </span></span>
    <span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">int</span> i;</pre>
    </div>
    <p><span style="font-family: 宋体">多行注释</span></p>
    <div class="cnblogs_code">
    <pre><span style="color: rgba(0, 128, 0, 1)">/*</span><span style="color: rgba(0, 128, 0, 1)"> 这是
    * 一段注释，
    * 它跨越了多个行
    </span><span style="color: rgba(0, 128, 0, 1)">*/</span> 
    <span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)"> f() {}
    }</span></pre>
    </div>
    <p><span style="font-family: 宋体">文档注释</span>&nbsp;</p>
    <div class="cnblogs_code">
    <pre><span style="color: rgba(0, 128, 0, 1)">/*</span><span style="color: rgba(0, 128, 0, 1)">* The first Thinking in Java example program.
    * Lists system information on current machine.
    * @author Bruce Eckel
    * @author </span><span style="color: rgba(0, 128, 0, 1); text-decoration: underline">http://www.BruceEckel.com</span><span style="color: rgba(0, 128, 0, 1)">
    * @version 1.0
    </span><span style="color: rgba(0, 128, 0, 1)">*/</span>
    <span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">class</span><span style="color: rgba(0, 0, 0, 1)"> Property {
    </span><span style="color: rgba(0, 128, 0, 1)">/*</span><span style="color: rgba(0, 128, 0, 1)">* Sole entry point to class &amp; application
    * @param args array of string arguments
    * @return No return value
    * @exception exceptions No exceptions thrown
    </span><span style="color: rgba(0, 128, 0, 1)">*/</span>
    <span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">static</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)"> main(String[] args) {
    System.</span><span style="color: rgba(0, 0, 255, 1)">out</span>.println(<span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> Date());
    Properties p </span>=<span style="color: rgba(0, 0, 0, 1)"> System.getProperties();
    p.list(System.</span><span style="color: rgba(0, 0, 255, 1)">out</span><span style="color: rgba(0, 0, 0, 1)">);
    System.</span><span style="color: rgba(0, 0, 255, 1)">out</span>.println(<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">--- Memory Usage:</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">);
    Runtime rt </span>=<span style="color: rgba(0, 0, 0, 1)"> Runtime.getRuntime();
    System.</span><span style="color: rgba(0, 0, 255, 1)">out</span>.println(<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">Total Memory = </span><span style="color: rgba(128, 0, 0, 1)">"</span>
    +<span style="color: rgba(0, 0, 0, 1)"> rt.totalMemory()
    </span>+ <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)"> Free Memory = </span><span style="color: rgba(128, 0, 0, 1)">"</span>
    +<span style="color: rgba(0, 0, 0, 1)"> rt.freeMemory());
    }</span><span style="color: rgba(128, 0, 128, 1)">59</span><span style="color: rgba(0, 0, 0, 1)">
    }</span></pre>
    </div>
    <p><span style="font-family: 宋体">对于单行和多行注释，被注释的文字，不会被</span><span style="font-family: Helvetica">JVM</span><span style="font-family: 宋体">解释执行；</span><span style="font-family: 宋体">对于文档注释，可以被</span><span style="font-family: Helvetica">JDK</span><span style="font-family: 宋体">提供的工具<span class="cnblogs_code">javadoc </span></span><span style="font-family: 宋体">所解析，生成一套以网页文件形式体现的该程序的说明文档；</span><span style="font-family: 宋体">单行注释可以嵌套使用，多行注释不能嵌套使用。</span></p>
    <h2><strong>关键字</strong></h2>
    <p><span style="font-family: 宋体">是被</span>Java<span style="font-family: 宋体">语言赋予特殊含义，具有专门用途的单词，比如</span><span style="font-family: Helvetica">class</span><span style="font-family: 宋体">，</span><span style="font-family: Helvetica">int</span><span style="font-family: 宋体">，</span><span style="font-family: Helvetica">double</span><span style="font-family: 宋体">均为</span><span style="font-family: Helvetica">Java</span><span style="font-family: 宋体">已经预设好的;</span></p>
    <p><span style="font-family: 宋体">组成关键字的字母全部小写</span><span style="font-family: Helvetica">&nbsp;,</span><span style="font-family: 宋体">注意</span><span style="font-family: Helvetica">String</span><span style="font-family: 宋体">不是关键字;</span></p>
    <p>goto<span style="font-family: 宋体">与</span><span style="font-family: Helvetica">const</span><span style="font-family: 宋体">是</span><span style="font-family: Helvetica">Java</span><span style="font-family: 宋体">中的保留字，即没有赋予特殊含义却仍被</span><span style="font-family: Helvetica">Java</span><span style="font-family: 宋体">占用的单词</span><span style="font-family: Helvetica">;</span></p>
    <h2><strong>标识符</strong></h2>
    <p><span style="font-family: 宋体">就是给类</span><span style="font-family: Helvetica">,</span><span style="font-family: 宋体">接口</span><span style="font-family: Helvetica">,</span><span style="font-family: 宋体">方法</span><span style="font-family: Helvetica">,</span><span style="font-family: 宋体">变量等起名字时使用的字符序列,</span><span style="font-family: 宋体">组成规则</span><span style="font-family: 宋体">只能包含下面的内容</span><span style="font-family: Helvetica">,</span><span style="font-family: 宋体">不能有其它内容</span><span style="font-family: Helvetica">:</span></p>
    <ul>
    <li>&nbsp;<span style="font-family: 宋体">英文大小写字母</span></li>
    <li><span style="font-family: 宋体">数字字符</span></li>
    <li>&nbsp;<span style="font-family: Helvetica">$</span><span style="font-family: 宋体">和</span><span style="font-family: Helvetica">_</span></li>
    </ul>
    <h3><span style="font-family: 宋体; line-height: 1.5">注意事项</span></h3>
    <ul>
    <li><span style="font-family: 宋体; line-height: 1.5">数字不能开头</span></li>
    <li><span style="font-family: 宋体; line-height: 1.5">不可以使用关键字</span></li>
    <li><span style="font-family: 宋体; line-height: 1.5">严格区分大小写，不限制长度</span></li>
    <li><span style="font-family: 宋体; line-height: 1.5">起名时，尽量见名知意</span></li>
    </ul>
    <h3>标识符中常见的命名规则</h3>
    <ul>
    <li><span style="font-family: 宋体">包名：多单词组成时所有字母均小写，使用</span>.<span style="font-family: 宋体">连接.比如：</span><span style="font-family: Helvetica">aaa.bbb.ccc</span></li>
    <li>类名&amp;接口名：大驼峰式。比如：AaaBbbCcc</li>
    <li>变量名&amp;方法名：小驼峰式。比如：aaaBbbCcc</li>
    <li>常量名：多单词组成是所有字母均大写，使用_连接。比如：AAA_BBB_CCC</li>
    </ul>
    <h2><span style="font-family: 宋体">数据类型</span></h2>
    <p><span style="font-family: 宋体">为什么有数据类型？</span></p>
    <p>Java<span style="font-family: 宋体">是强类型语言，对于每一种数据都定义了明确的具体数据类型，</span>变量必须要有明确的类型，什么类型的变量装载什么类型的数据。</p>
    <h3><span style="font-family: 宋体">数据类型的分类</span></h3>
    <p><span style="font-family: 宋体">基本数据类型</span></p>
    <p><span style="font-family: 宋体">基本数据类型是</span><span style="font-family: Helvetica">Java</span><span style="font-family: 宋体">语言中内置的类型，分别是整数类型、小数类型、字符类型、布尔类型。</span></p>
    <p>这四类基本类型是最简单、最基础的类型。</p>
    <ul>
    <li><span style="font-family: 宋体">整数</span><span style="font-family: Helvetica">(byte</span><span style="font-family: 宋体">、</span><span style="font-family: Helvetica">short</span><span style="font-family: 宋体">、</span><span style="font-family: Helvetica">int</span><span style="font-family: 宋体">、</span><span style="font-family: Helvetica">long)，</span><span style="font-family: 宋体">默认的整数类型是</span>int<span style="font-family: 宋体">类型，long类型需</span><span style="font-family: 宋体">添加"L"</span><span style="font-family: 宋体">后缀。</span></li>
    <li><span style="font-family: 宋体">小数</span><span style="font-family: Helvetica">(float</span><span style="font-family: 宋体">、</span><span style="font-family: Helvetica">double)</span><span style="font-family: 宋体">、字符类型</span><span style="font-family: Helvetica">(char)，默认</span><span style="font-family: 宋体">的浮点类型是</span>double<span style="font-family: 宋体">类型。</span><span style="font-family: 宋体">在</span>Java<span style="font-family: 宋体">中所有没有后缀以及使用“</span><span style="font-family: Calibri">D</span><span style="font-family: 宋体">”后缀（小写也可以，但建议使用大写）的小数都是</span><span style="font-family: Calibri">double</span><span style="font-family: 宋体">类型；</span><span style="font-family: Calibri">float</span><span style="font-family: 宋体">类型常量必须添加“</span><span style="font-family: Calibri">F</span><span style="font-family: 宋体">”后缀</span></li>
    <li><span style="font-family: 宋体">字符类型（char）</span></li>
    <li><span style="font-family: 宋体">布尔类型</span><span style="font-family: Helvetica">(boolean)</span></li>
    </ul>
    <p><span style="font-family: 宋体">引用数据类型</span></p>
    <p><span style="font-family: 宋体">引用数据类型是强大的数据类型，它是基于基本数据类型创建的。</span><span style="font-family: Helvetica">JavaSE</span><span style="font-family: 宋体">中提供了一个超级类库，类库中包含了近万种引用数据类型。比如：</span><span style="font-family: 宋体">数组、类、接口。</span></p>
    <h2><strong><span style="font-family: 宋体">常量</span></strong></h2>
    <p><span style="font-family: 宋体">常量就是不变的数据量</span><span style="font-family: Helvetica">, </span><span style="font-family: 宋体">在程序执行的过程中其值不可以发生改变</span></p>
    <h3><span style="font-family: 宋体">常量分类</span></h3>
    <p><span style="font-family: 宋体">整数类型</span></p>
    <ul>
    <li><span style="font-family: 宋体">十进制表示方式：正常数字，如 </span><span style="font-family: Helvetica">13</span><span style="font-family: 宋体">、</span><span style="font-family: Helvetica">25</span><span style="font-family: 宋体">等</span></li>
    <li><span style="font-family: 宋体">二进制表示方式：以</span><span style="font-family: Helvetica">0b(0B)</span><span style="font-family: 宋体">开头，如</span><span style="font-family: Helvetica">0b1011 </span><span style="font-family: 宋体">、</span><span style="font-family: Helvetica">0B1001 </span></li>
    <li><span style="font-family: 宋体">十六进制表示方式：以</span><span style="font-family: Helvetica">0x(0X)</span><span style="font-family: 宋体">开头，数字以</span><span style="font-family: Helvetica">0-9</span><span style="font-family: 宋体">及</span><span style="font-family: Helvetica">A-F</span><span style="font-family: 宋体">组成 &nbsp;如</span><span style="font-family: Helvetica">0x23A2</span><span style="font-family: 宋体">、</span><span style="font-family: Helvetica">0xa</span><span style="font-family: 宋体">、</span><span style="font-family: Helvetica">0x10 </span></li>
    <li><span style="font-family: 宋体">八进制表示方式：以</span><span style="font-family: Helvetica">0</span><span style="font-family: 宋体">开头，如</span><span style="font-family: Helvetica">01</span><span style="font-family: 宋体">、</span><span style="font-family: Helvetica">07</span><span style="font-family: 宋体">、</span><span style="font-family: Helvetica">0721</span></li>
    </ul>
    <p><span style="font-family: 宋体">小数类型，</span><span style="font-family: 宋体">如</span><span style="font-family: Helvetica">1.0</span><span style="font-family: 宋体">、</span><span style="font-family: Helvetica">-3.15</span><span style="font-family: 宋体">、</span><span style="font-family: Helvetica">3.168</span><span style="font-family: 宋体">等</span></p>
    <p><span style="font-family: 宋体">布尔类型，</span>&nbsp;true<span style="font-family: 宋体">、</span><span style="font-family: Helvetica">false</span></p>
    <p><span style="font-family: 宋体">字符类型，</span><span style="font-family: 宋体">字符必须使用</span>’’ 包裹，并且其中只能且仅能包含一个字符。<span style="font-family: 宋体">如</span><span style="line-height: 1.5">'a'</span><span style="font-family: 宋体">，</span><span style="font-family: Helvetica">'A', '0', '</span><span style="font-family: 宋体">家</span><span style="font-family: Helvetica">'</span></p>
    <p>字符串类型，<span style="font-family: 宋体">一种引用类型，</span><span style="font-family: 宋体">字符串必须使用</span>""包裹，其中可以包含<span style="font-family: Helvetica">0~N</span><span style="font-family: 宋体">个字符。</span><span style="font-family: 宋体">如"</span>我爱<span style="font-family: Helvetica">Java"</span><span style="font-family: 宋体">，"</span><span style="font-family: Helvetica">0123"</span><span style="font-family: 宋体">，""，"</span><span style="font-family: Helvetica">null"</span></p>
    <h3><strong><span style="font-family: 宋体">在程序中输出</span>Java<span style="font-family: 宋体">中的常量</span></strong></h3>
    <div class="cnblogs_code">
    <pre><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">class</span><span style="color: rgba(0, 0, 0, 1)"> Main {
        </span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">static</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)"> main(String[] args) {
            </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">输出整数 十进制</span>
            System.<span style="color: rgba(0, 0, 255, 1)">out</span>.println(<span style="color: rgba(128, 0, 128, 1)">50</span>);<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">50
            </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">输出整数，二进制, 数字开头0B</span>
            System.<span style="color: rgba(0, 0, 255, 1)">out</span>.println(0B11);<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">3
            </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">输出整数，八进制，数字开头0</span>
            System.<span style="color: rgba(0, 0, 255, 1)">out</span>.println(<span style="color: rgba(128, 0, 128, 1)">051</span>);<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">41
            </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">输出整数，十六进制，数组开头0X  0-9 A-F</span>
            System.<span style="color: rgba(0, 0, 255, 1)">out</span>.println(<span style="color: rgba(128, 0, 128, 1)">0XE</span>);<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">14
            </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">输出浮点数据</span>
            System.<span style="color: rgba(0, 0, 255, 1)">out</span>.println(<span style="color: rgba(128, 0, 128, 1)">5.0</span>);<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">5.0
            </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">输出布尔数据，只有2个值，true，false 关键字</span>
            System.<span style="color: rgba(0, 0, 255, 1)">out</span>.println(<span style="color: rgba(0, 0, 255, 1)">true</span>);<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">true</span>
            System.<span style="color: rgba(0, 0, 255, 1)">out</span>.println(<span style="color: rgba(0, 0, 255, 1)">false</span>);<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">false
            </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">输出字符常量，单引号包裹，只能写1个字符</span>
            System.<span style="color: rgba(0, 0, 255, 1)">out</span>.println(<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">a</span><span style="color: rgba(128, 0, 0, 1)">'</span>);<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">a
            </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">输出字符串常量，双引号包裹，可以写0-n个字符</span>
            System.<span style="color: rgba(0, 0, 255, 1)">out</span>.println(<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">HelloWorld</span><span style="color: rgba(128, 0, 0, 1)">"</span>);<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">HelloWorld</span>
    <span style="color: rgba(0, 0, 0, 1)">    }
    }</span></pre>
    </div>
    <h2><strong>变量</strong></h2>
    <h3><strong>什么是变量?</strong></h3>
    <p>变量是一个内存中的小盒子（小容器），容器是什么？生活中也有很多容器，例如水杯是容器，用来装载水；你家里的大衣柜是容器，用来装载衣裤；饭盒是容器，用来装载饭菜。</p>
    <p>那么变量是装载什么的呢？答案是数据！结论：变量是内存中装载数据的小盒子，你只能用它来存数据和取数据。</p>
    <h3>定义变量</h3>
    <div class="cnblogs_code">
    <pre>数据类型  变量名  =<span style="color: rgba(0, 0, 0, 1)">  数据值；
    </span><span style="color: rgba(0, 0, 255, 1)">int</span>         a    =  <span style="color: rgba(128, 0, 128, 1)">100</span>;</pre>
    </div>
    <h3><strong>变量使用的注意事项</strong></h3>
    <p class="16">变量定义后可以不赋值，使用时再赋值。不赋值不能使用。</p>
    <div class="cnblogs_code">
    <pre><span style="color: rgba(0, 0, 255, 1)">int</span><span style="color: rgba(0, 0, 0, 1)"> x;
    x </span>= <span style="color: rgba(128, 0, 128, 1)">20</span>; <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">为x赋值20</span></pre>
    </div>
    <p class="16">变量使用时有作用域的限制。</p>
    <div class="cnblogs_code">
    <pre><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">static</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)"> main(String[] args) {
        </span><span style="color: rgba(0, 0, 255, 1)">int</span> x = 20<span style="color: rgba(0, 0, 0, 1)">;
        {
            </span><span style="color: rgba(0, 0, 255, 1)">int</span> y = 20<span style="color: rgba(0, 0, 0, 1)">;
        }
        System.out.println(x);</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">读取x变量中的值，再打印</span>
        System.out.println(y);<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">读取y变量中的值失败，失败原因，找不到y变量，因为超出了y变量作用范围，所以不能使用y变量</span>
    }</pre>
    </div>
    <p class="16">变量不可以重复定义。</p>
    <div class="cnblogs_code">
    <pre><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">static</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)"> main(String[] args){
          </span><span style="color: rgba(0, 0, 255, 1)">int</span> x = 10<span style="color: rgba(0, 0, 0, 1)">;
          </span><span style="color: rgba(0, 0, 255, 1)">double</span> x = 5.5;<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">编译失败，变量重复定义</span>
    }</pre>
    </div>
    <h2>数据类型转换</h2>
    <p>不同类型的变量可以在一起运算，但要先进行类型转换再运算。</p>
    <ul>
    <li><span style="font-family: 宋体">范围小的数据类型值（如</span>byte<span style="font-family: 宋体">），可以直接转换为范围大的数据类型值（如</span><span style="font-family: Calibri">int</span><span style="font-family: 宋体">）；</span></li>
    <li><span style="font-family: 宋体">范围大的数据类型值（如</span>int<span style="font-family: 宋体">），不可以直接转换为范围小的数据类型值（如</span><span style="font-family: Calibri">byte</span><span style="font-family: 宋体">）</span></li>
    </ul>
    <p>数据范围从小到大依次列出：byte -&gt; short -&gt; int -&gt; long -&gt; float -&gt; double</p>
    <p>两种方式的数据类型转换</p>
    <p class="16">自动类型转换：表示范围小的数据类型转换成范围大的数据类型。格式：</p>
    <div class="cnblogs_code">
    <pre>范围大的数据类型 变量 =<span style="color: rgba(0, 0, 0, 1)"> 范围小的数据类型值；
    </span><span style="color: rgba(0, 0, 255, 1)">比如：double</span> d = 1000; </pre>
    </div>
    <p class="16">强制类型转换：表示范围大的数据类型转换成范围小的数据类型</p>
    <div class="cnblogs_code">
    <pre>范围小的数据类型  变量 =<span style="color: rgba(0, 0, 0, 1)"> (范围小的数据类型) 范围大的数据类型值;
    </span><span style="color: rgba(0, 0, 255, 1)">比如：int</span>  i = (<span style="color: rgba(0, 0, 255, 1)">int</span>)6.718;   <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">i的值为6</span></pre>
    </div>
    <h2>运算符</h2>
    <h3>算数运算符</h3>
    <p><span class="fontstyle0">加号（ +）、减号和负号（ -）、乘号（ *）、除号（ /）、取模（%）、</span>自增（++）、自减（--）<span class="fontstyle0">以及等号（ =）的用法与其他所有编程语言都是类似的 。</span></p>
    <p class="16">++,--运算符后置时，先使用变量a原有值参与运算操作，运算操作完成后，变量a的值自增1或者自减1。</p>
    <p class="16">l&nbsp;++，--运算符前置时，先将变量a的值自增1或者自减1，然后使用更新后的新值参与运算操作。</p>
    <h3 class="16">赋值运算符</h3>
    <p>赋值（=）、加后赋值（+=）、减后赋值（-=）、乘后赋值（*=）、整除后赋值（/=）<span style="font-family: 宋体">取模后赋值（</span>%=<span style="font-family: 宋体">）的用法与其他所有编程语言都是类似的 。</span></p>
    <h3>关系运算符</h3>
    <p class="16"><span style="font-family: 宋体">等于（</span>==） &nbsp;不等于（!=） 小于（&lt;） 大于（&gt;） &nbsp;小于等于<span style="font-family: 宋体">（</span>&lt;=） 大于等于<span style="font-family: 宋体">（</span>&gt;=）的用法与其他所有编程语言都是类似的 。</p>
    <h3><strong>逻辑运算符</strong></h3>
    <p><span style="font-family: 宋体">与（</span>&amp;&amp;<span style="font-family: 宋体">）、或（</span><span style="font-family: Calibri">||</span><span style="font-family: 宋体">）、非（</span><span style="font-family: Calibri">!</span><span style="font-family: 宋体">）的用法与其他所有编程语言都是类似的 。</span></p>
    <p>短路：当使用与或者或时，只要能判断出结果则后边的部分就不再判断。</p>
    <h3><strong>三元运算符</strong></h3>
    <p>(<span style="font-family: 宋体">条件表达式</span><span style="font-family: Calibri">)</span><span style="font-family: 宋体">？表达式</span><span style="font-family: Calibri">1</span><span style="font-family: 宋体">：表达式</span><span style="font-family: Calibri">2</span><span style="font-family: 宋体">；</span></p>
    <div class="cnblogs_code">
    <pre><span style="color: rgba(0, 0, 255, 1)">int</span> n = (3&gt;2 &amp;&amp; 4&gt;6) ? 100 : 200<span style="color: rgba(0, 0, 0, 1)">;
    </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">逻辑运算后的结果为false，运算结果为表达式2的值200,然后将结果200赋值给了变量n</span></pre>
    </div>
    <h2>商场库存清单案例</h2>
    <p>案例输出结果如下：</p>
    <p><img src="https://images2015.cnblogs.com/blog/612774/201707/612774-20170702005415883-632304767.png" alt=""></p>
    <h3><strong>案例需求分析</strong></h3>
    <p><span style="line-height: 1.5">观察清单后，可将清单分解为三个部分（清单顶部、清单中部、清单底部）</span></p>
    <p>清单顶部为固定的数据，直接打印即可<br>清单中部为商品，为变化的数据，需要记录商品信息后，打印，经过观察，我们确定一项商品应该有如下几个属性：</p>
    <ul>
    <li>			品牌型号: 即商品名称，String型</li>
    <li>			尺寸：物品大小，double型</li>
    <li>			价格：物品单价，double型</li>
    <li>			配置：这一项为每种商品的配置信息，String型</li>
    <li>			库存数：这一项为每种商品的库存个数，int型</li>
    
    </ul>
    <p>清单底部包含了统计操作，需经过计算后，打印，我们发现两个单独的可变化量：</p>
    <ul>
    <li>			总库存数：所有商品总个数，int型</li>
    <li>			库存商品总金额：所有商品金额，double型</li>
    
    </ul>
    <div class="cnblogs_code">
    <pre><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">class</span><span style="color: rgba(0, 0, 0, 1)"> Main {
        </span><span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">static</span> <span style="color: rgba(0, 0, 255, 1)">void</span><span style="color: rgba(0, 0, 0, 1)"> main(String[] args) {
            </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">苹果笔记本电脑</span>
            String macBrand = "MacBookAir"<span style="color: rgba(0, 0, 0, 1)">;
            </span><span style="color: rgba(0, 0, 255, 1)">double</span> macSize = 13.3<span style="color: rgba(0, 0, 0, 1)">;
            </span><span style="color: rgba(0, 0, 255, 1)">double</span> macPrice = 6988.88<span style="color: rgba(0, 0, 0, 1)">;
            </span><span style="color: rgba(0, 0, 255, 1)">int</span> macCount = 5<span style="color: rgba(0, 0, 0, 1)">;
    
            </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">联想Thinkpad笔记本电脑</span>
            String thinkpadBrand = "ThinkpadT450"<span style="color: rgba(0, 0, 0, 1)">;
            </span><span style="color: rgba(0, 0, 255, 1)">double</span> thinkpadSize = 14.0<span style="color: rgba(0, 0, 0, 1)">;
            </span><span style="color: rgba(0, 0, 255, 1)">double</span> thinkpadPrice = 5999.99<span style="color: rgba(0, 0, 0, 1)">;
            </span><span style="color: rgba(0, 0, 255, 1)">int</span> thinkpadCount = 10<span style="color: rgba(0, 0, 0, 1)">;
    
            </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">华硕ASUS笔记本电脑</span>
            String ASUSBrand = "ASUS-FL5800"<span style="color: rgba(0, 0, 0, 1)">;
            </span><span style="color: rgba(0, 0, 255, 1)">double</span> ASUSSize = 15.6<span style="color: rgba(0, 0, 0, 1)">;
            </span><span style="color: rgba(0, 0, 255, 1)">double</span> ASUSPrice = 4999.50<span style="color: rgba(0, 0, 0, 1)">;
            </span><span style="color: rgba(0, 0, 255, 1)">int</span> ASUSCount = 18<span style="color: rgba(0, 0, 0, 1)">;
            </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">统计所有库存商品数量与金额
            </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">统计库存总个数、库存总金额</span>
            <span style="color: rgba(0, 0, 255, 1)">int</span> totalCount = macCount + thinkpadCount +<span style="color: rgba(0, 0, 0, 1)"> ASUSCount;
            </span><span style="color: rgba(0, 0, 255, 1)">double</span> totalMoney = (macCount * macPrice) + (thinkpadCount * thinkpadPrice) + (ASUSCount *<span style="color: rgba(0, 0, 0, 1)"> ASUSPrice);
            </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">打印库存清单顶部信息</span>
            System.out.println("------------------------------商城库存清单-----------------------------"<span style="color: rgba(0, 0, 0, 1)">);
            System.out.println(</span>"品牌型号    尺寸    价格    库存数"<span style="color: rgba(0, 0, 0, 1)">);
            </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">打印库存清单中部信息</span>
            System.out.println(macBrand + "    " + macSize + "    " + macPrice + "    " +<span style="color: rgba(0, 0, 0, 1)"> macCount);
            System.out.println(thinkpadBrand </span>+ "    " + thinkpadSize + "    " + thinkpadPrice + "    " +<span style="color: rgba(0, 0, 0, 1)"> thinkpadCount);
            System.out.println(ASUSBrand </span>+ "    " + ASUSSize + "    " + ASUSPrice + "    "+<span style="color: rgba(0, 0, 0, 1)">ASUSCount);
            </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">打印库存清单底部信息</span>
            System.out.println("-----------------------------------------------------------------------"<span style="color: rgba(0, 0, 0, 1)">);
            System.out.println(</span>"总库存数：" +<span style="color: rgba(0, 0, 0, 1)"> totalCount);
            System.out.println(</span>"库存商品总金额：" +<span style="color: rgba(0, 0, 0, 1)"> totalMoney);
        }
    }</span></pre>
    </div>
    <p>&nbsp;</p>
    </div>

</body>
</html>